/*  
     PlAr is Platform Arena: a 2D multiplayer shooting game
     Copyright (C) 2009 Ragagnin Antonio <spocchio@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package res.elements;



import plar.core.Common;
import plar.core.Element;

import plar.core.Action;
import plar.core.Parameters;

import plar.core.Gun;

import plar.core.Player;
import plar.core.Shoot;

import plar.core.Sprite;
import res.elements.Mine;


import java.util.ArrayList;
import plar.core.Level;
import java.awt.Polygon;

import org.jbox2d.collision.AABB;
import org.jbox2d.common.Vec2;

public class GunMine extends Gun {
	
	public GunMine(Player player) {
super(player);
		 setProperty("gunName","Mine");
		 setProperty("gunUseAmmo",10);
		 setProperty("damageRange",new Vec2(2.5f,2.5f));
	}
	public void fire() {
		Common.info(5,"fire!");
		if (getAmmo() >= (Integer)getProperty("gunUseAmmo") ) {
			setProperty("isFiring", true);
			Mine shoot = new Mine();
			Common.info(5,"new mine");
			shoot.actions.removeAction("nogravity");
			this.initializeShoot(shoot);
			
			shoot.addSprite(new Sprite("res/elements/mine.png",400));
			Sprite sprite = new Sprite("res/elements/explosion0.png",200);
			sprite.offsetx=-2.5f;
			sprite.offsety=-2.5f;
			sprite.sizex=5f;
			sprite.sizey=5f;
			shoot.addSprite(sprite);
			
			shoot.setProperty("lifeTime",800);
			shoot.setProperty("explosionTime",200);
			Vec2 range = (Vec2)(getProperty("damageRange"));
			AABB rect = new AABB();
			rect.lowerBound=new Vec2(-range.x,-range.y);
			rect.upperBound=new Vec2(range.x,range.y);
			shoot.setProperty("explosionRelativeRectangle",rect);
			shoot.setProperty("explosionDamage",2);
			
			
			
			
			shoot.Initialize();

			

			addAmmo(-(Integer)getProperty("gunUseAmmo") );
			

		}
	}
	


}
